﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Uinside.CreditSystem.DomainModels.Models
{
    public class Customer : BaseModel
    {

        private ObservableCollection<Order> _borrowerOrders;
        public virtual ObservableCollection<Order> BorrowerOrder
        {
            get
            {

                return _borrowerOrders;
            }
            set
            {
                SetField(ref _borrowerOrders, value, "BorrowerOrder");
            }
        }

        private ObservableCollection<Order> _lenderOrder;
        public virtual ObservableCollection<Order> LenderOrders
        {
            get
            {

                return _lenderOrder;
            }
            set
            {
                SetField(ref _lenderOrder, value, "LenderOrders");
            }
        }


        private ObservableCollection<Payment> _deposits;
        [NotMapped]
        public ObservableCollection<Payment> Deposits
        {
            get
            {
                if (_deposits == null)
                {
                    if (this.BorrowerPayments == null)
                         _deposits = new ObservableCollection<Payment>();
                    else
                    {
                        _deposits = new ObservableCollection<Payment>(this.BorrowerPayments.Union(LenderPayments).Where(i => (i.Type.Type == 3 && (i.Type.Value == 1 || i.Type.Value == 2))));
                    }
                }
                return _deposits;
            }
        }

        private ObservableCollection<Payment> _borrowerpayments;
        public virtual ObservableCollection<Payment> BorrowerPayments
        {
            get
            {

                return _borrowerpayments;
            }
            set
            {
                SetField(ref _borrowerpayments, value, "BorrowerPayments");
            }
        }

        private ObservableCollection<Payment> _lenderpayments;
        public virtual ObservableCollection<Payment> LenderPayments
        {
            get
            {

                return _lenderpayments;
            }
            set
            {
                SetField(ref _lenderpayments, value, "LenderPayments");
            }
        }


        private string _customerNumber;
        [StringLength(20)]
        public string CustomerNumber
        {
            get { return _customerNumber; }
            set { SetField(ref _customerNumber, value, "CustomerNumber"); }
        }

        private string _companyName;
        [StringLength(100)]
        [Required]
        public string CompanyName
        {
            get { return _companyName; }
            set
            {
                SetField(ref _companyName, value, "CompanyName");
            }
        }

        private string _companyAddress;
        [StringLength(100)]
        [Required]
        public string CompanyAddress
        {
            get { return _companyAddress; }
            set
            {
                SetField(ref _companyAddress, value, "CompanyAddress");
            }
        }

        private string _companyPostCode;
        [StringLength(6)]
        public string CompanyPostCode
        {
            get { return _companyPostCode; }
            set { SetField(ref _companyPostCode, value, "CompanyPostCode"); }
        }

        private string _companyPortalUrl;
        [StringLength(100)]
        public string CompanyPortalUrl
        {
            get { return _companyPortalUrl; }
            set { SetField(ref _companyPortalUrl, value, "CompanyPortalUrl"); }
        }

        private string _companyEmail;
        [StringLength(100)]
        public string CompanyEmail
        {
            get { return _companyEmail; }
            set { SetField(ref _companyEmail, value, "CompanyEmail"); }
        }

        private string _companyPhone;
        [StringLength(20)]
        public string CompanyPhone
        {
            get { return _companyPhone; }
            set { SetField(ref _companyPhone, value, "CompanyPhone"); }
        }

        private Image _companyLogo;
        public virtual Image CompanyLogo
        {
            get { return _companyLogo; }
            set { SetField(ref _companyLogo, value, "CompanyLogo"); }
        }

        private string _contactName;
        [StringLength(20)]
        public string ContactName
        {
            get { return _contactName; }
            set { SetField(ref _contactName, value, "ContactName"); }
        }

        private string _contactPhone;
        [StringLength(20)]
        public string ContactPhone
        {
            get { return _contactPhone; }
            set { SetField(ref _contactPhone, value, "ContactPhone"); }
        }

        private string _contactEmail;
        [StringLength(100)]
        public string ContactEmail
        {
            get { return _contactEmail; }
            set { SetField(ref _contactEmail, value, "ContactEmail"); }
        }

        private string _contactQQ;
        [StringLength(20)]
        public string ContactQQ
        {
            get { return _contactQQ; }
            set { SetField(ref _contactQQ, value, "ContactQQ"); }
        }

        private string _contactIdNumber;
        [StringLength(20)]
        public string ContactIdNumber
        {
            get { return _contactIdNumber; }
            set { SetField(ref _contactIdNumber, value, "ContactIdNumber"); }
        }


        private ObservableCollection<Image> _contactIdImages;
        public virtual ObservableCollection<Image> ContactIdImages
        {
            get { return _contactIdImages; }
            set
            {
                SetField(ref _contactIdImages, value, "ContactIdImages");
            }
        }
        //only used for company
        private decimal _capital;
        public decimal Capital
        {
            get { return _capital; }
            set { SetField(ref _capital, value, "Capital"); }
        }

        private ObservableCollection<Image> _qualificationImages;
        public virtual ObservableCollection<Image> QualificationImages
        {
            get { return _qualificationImages; }
            set
            {
                SetField(ref _qualificationImages, value, "QualificationImages");
            }
        }

        private ObservableCollection<BankAccount> _bankAccounts;
        public virtual ObservableCollection<BankAccount> BankAccounts
        {
            get { return _bankAccounts; }
            set
            {
                SetField(ref _bankAccounts, value, "BankAccounts");
            }
        }


    }
}
